/**
 * 
 */
package org.ranch.model;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 * This entity captures all the basic data neede about an individual. Eg Farm manager, Vet doctor
 *
 */
@Entity
@Table(name = "persons")
public class Person extends User {

    /**
     * The religious name
     */
    private String firstName;
    /**
     * The sir-name
     */
    private String lastName;
    /**
     * The gender of this person, its set to female by default
     */
    private Gender gender = Gender.UNKNOWN;
    /**
     * Any other info to be captured about this person
     */
    private String otherInformation;
    /**
     * The contact addresses for this person
     */
    private Address addresses;
    /**
     * The people to be contacted incase of any emergency about this person
     */
    private List<Person> nextOfKins;
    /**
     * One's nationality
     */
    private String nationality;
    /**
     * The date when this person was born
     */
    private Date dateOfBirth;
    /**
     * represents the profile picture of the person
     */
    private byte[] profilePicture = new byte[1];
    
    /**
     * Represents the reponsibility held by this person
     */
    private Concept responsibility;

    /**
     * Creates a new instance of Person
     */
    public Person() {
        super();
    }

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "address_id", nullable = true)
    public Address getAddresses() {
        return addresses;
    }

    public void setAddresses(Address addresses) {
        this.addresses = addresses;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "date_of_birth", nullable = false)
    public Date getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(Date dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    @Column(name = "first_name", nullable = true)
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Enumerated(EnumType.ORDINAL)
    @Column(name = "gender", nullable = false)
    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    @Column(name = "last_name", nullable = true)
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Column(name = "nationality", nullable = true)
    public String getNationality() {
        return nationality;
    }

    public void setNationality(String nationality) {
        this.nationality = nationality;
    }

    @OneToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "person_next_of_kin", joinColumns = @JoinColumn(name = "person_id"),
    inverseJoinColumns = @JoinColumn(name = "next_of_kin_id"))
    public List<Person> getNextOfKins() {
        return nextOfKins;
    }

    public void setNextOfKins(List<Person> nextOfKins) {
        this.nextOfKins = nextOfKins;
    }

    @Column(name = "other_information", nullable = true)
    public String getOtherInformation() {
        return otherInformation;
    }

    public void setOtherInformation(String otherInformation) {
        this.otherInformation = otherInformation;
    }

    @Lob()
    @Column(name = "picture", nullable = true)
    public byte[] getProfilePicture() {
        return profilePicture;
    }

    public void setProfilePicture(byte[] profilePicture) {
        this.profilePicture = profilePicture;
    }

    /**
     * @return the responsibility
     */
    @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
    @JoinColumn(name = "responsibility_id", nullable = true)
    public Concept getResponsibility() {
        return responsibility;
    }

    /**
     * @param responsibility the responsibility to set
     */
    public void setResponsibility(Concept responsibility) {
        this.responsibility = responsibility;
    }
    
    @Transient
    public String getFullNames(){
	return getFirstName() +" "+ getLastName();
    }
}
